package com.hue.concurrent.day04;

/*
    多个不相干锁：
        降低锁的粒度
 */
public class Demo03 {
    public static void main(String[] args) {
        Room room = new Room();
        new Thread(room::study).start();

        new Thread(room::sleep).start();
    }

    public static class Room {
        private final Object bedRoom = new Object();
        private final Object bookRoom = new Object();

        public void study() {
            synchronized (bookRoom) {
                System.out.println("study...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public void sleep() {
            synchronized (bedRoom) {
                System.out.println("sleep...");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
